<?php
namespace app\wechat\controller;

use app\api\service\Dealer;
class DMember extends WCommon
{
    public function index()
    {
        $member_id = session('member_id');
        // 检查是否有合伙人权限
        $dealer = db('dealer')->where('member_id', $member_id)->find();
        $this->assign('dealer', $dealer);
        if (!$dealer) {
            // 没有申请 转入申请提示页面
            return view('d_member/audit');
        } else if ($dealer['audit_status'] != 4) {
            // 审核状态页面
            $this->redirect('d_certification/audit_status', ['status' => $dealer['audit_status'], 'msg' => $dealer['msg']]);
        }

        $map['m.openid'] = session('openid');
        $map['m.band_status'] = 1;
        $member_info = db('member')->alias('m')->field('m.*, mr.signature, mr.nickname, mr.headimgurl')
            ->join("mob_member_role_info mr", "m.id = mr.member_id and mr.type = 2", 'LEFT')->where($map)->find();
        
        // 如果头像和昵称不存在则使用微信头像和昵称
        $member_info['nickname'] ? $member_info['nickname'] : $member_info['nickname'] = session('nickname');
        $member_info['headimgurl'] ? $member_info['headimgurl'] : $member_info['headimgurl'] = session('headimgurl');

        $this->assign('member', $member_info);

        // 获取经销商首页数据
        $param = [
            'member_id' => session('member_id'),
            'terrace' => 'weixin'
        ];
        $data = Dealer::dealer_index_data($param);
        $this->assign('data', $data['data']);
        return view();
    }

    // 实名认证
    public function certification() {
        return view();
    }

    // 店铺信息
    public function dealer_info() {
        // 获取经销商首页数据
        $param = [
            'dealer_id' => input('param.id')
        ];
        $data = Dealer::get_dealer_info($param);
        $this->assign('data', $data['data']);
        return view();
    }
}
